package leetcode;

/**
 * Created by Ghost on 2014/9/30 0030.
 */
public class Divide_Two_Integers {

    public static int divide(int dividend, int divisor) {

        int flag = 1;
        if((dividend <0 && divisor >0) || (dividend > 0 && divisor < 0)){
            flag = -1;
        }
        dividend = Math.abs(dividend);
        divisor = Math.abs(divisor);
        if(divisor==1)
            return flag*dividend;
        int n = 0;
        while(dividend >= divisor){
            n++;
            dividend -= divisor;
        }
        return n*flag;
    }
    public static void main(String[] args){
        System.out.println(divide(2147483647,2));
    }
}
